<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button onclick="routerWay()">页面路由跳转方法</button>
    <button onclick="hashWay()">hash跳转方法</button>
    <button onclick="backWay()">backWay方法</button>
    <button onclick="pushState()">pushState方法</button>
    <button onclick="replaceState()">replaceState方法</button>
    <script>
        function routerWay() {
            window.location.href = 'http://www.baidu.com';
        }

        function hashWay() {
            window.location = '#hash';
            // hash变化时触发
            window.onhashchange = function () {
                //  console.log('current hash:', window.location.hash);
            }
        }
        // 实现后退功能
        function backWay() {
            // history.back();
            history.go(-1);
        }

        function pushState() {
            history.pushState(null, null, '?path1');
        }

        function replaceState() {
            history.pushState(null, null, '?path2');
        }
    </script>
</body>

</html>